﻿@namespace AntSK.Pages.Setting.AIModel
@using AntSK.Domain.Repositories
@using AntSK.Domain.Domain.Model.Enum
@page "/modelmanager/modellist"
@inject NavigationManager NavigationManager
@using AntSK.Services.Auth
@inherits AuthComponentBase
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize(Roles = "AntSKAdmin")]

<div>
    <PageContainer Title="模型管理">
        <ChildContent>
            <div class="standardList">

                <Card Class="listCard"
                      Title="模型列表"
                      Style="margin-top: 24px;"
                      BodyStyle="padding: 0 32px 40px 32px">
                    <Extra>
                        <div class="extraContent">

                            <Search Class="extraContentSearch" Placeholder="查询" @bind-Value="_searchKeyword" OnSearch="OnSearch" />
                        </div>
                    </Extra>
                    <ChildContent>
                        <Button Type="dashed"
                                Style="width: 100%; margin-bottom: 8px;"
                                OnClick="AddModel">
                            <Icon Type="plus" Theme="outline" />
                            新增模型
                        </Button>

                        <AntList TItem="AIModels"
                                 DataSource="_data"
                                 ItemLayout="ListItemLayout.Horizontal">
                            <ListItem Actions="new[] {
                            edit(()=> Edit(context.Id)),
                            delete(async ()=>await Delete(context.Id))
                             }" Style="width:100%">
                                <div class="listContent" style="width:100%">
                                    <div class="listContentItem" style="width:20%">
                                        <b>模型ID</b>
                                        <p title="@context.Id">@context.Id</p>
                                    </div>
                                    <div class="listContentItem" style="width:5%">
                                        <b>模型描述</b>
                                        <p title="@context.ModelDescription">@context.ModelDescription</p>
                                    </div>
                                    <div class="listContentItem" style="width:10%">
                                        <b>AI类型</b>
                                        <p>
                                            @if (context.AIType == AIType.OpenAI)
                                            {
                                                <Tag Color="@PresetColor.Pink.ToString()">OpenAI</Tag>
                                            }
                                            else if (context.AIType == AIType.AzureOpenAI)
                                            {
                                                <Tag Color="@PresetColor.Red.ToString()">AzureOpenAI</Tag>
                                            }
                                            else if (context.AIType == AIType.SparkDesk)
                                            {
                                                <Tag Color="@PresetColor.Cyan.ToString()">SparkDesk</Tag>
                                            }
                                            else if (context.AIType == AIType.Mock)
                                            {
                                                <Tag Color="@PresetColor.Green.ToString()">Mock</Tag>
                                            }
                                            else if (context.AIType == AIType.LLamaFactory)
                                            {
                                                <Tag Color="@PresetColor.Blue.ToString()">LLamaFactory</Tag>
                                            }
                                            else if (context.AIType == AIType.BgeEmbedding)
                                            {
                                                <Tag Color="@PresetColor.Purple.ToString()">BgeEmbedding</Tag>
                                            }
                                            else if (context.AIType == AIType.BgeRerank)
                                            {
                                                <Tag Color="@PresetColor.GeekBlue.ToString()">BgeRerank</Tag>
                                            }
                                            else if (context.AIType == AIType.Ollama || context.AIType == AIType.OllamaEmbedding)
                                                            {
                                                <Tag Color="@PresetColor.Pink.ToString()">Ollama</Tag>
                                            }
                                        </p>
                                    </div>


                                    <div class="listContentItem" style="width:10%">
                                        <b>模型类别</b>
                                        <p>
                                            @if (context.AIModelType == AIModelType.Chat)
                                            {
                                                <Tag Color="@PresetColor.Yellow.ToString()">会话模型</Tag>
                                            }
                                            else if (context.AIModelType == AIModelType.Embedding)
                                            {
                                                <Tag Color="@PresetColor.Green.ToString()">向量模型</Tag>
                                            }
                                            else if (context.AIModelType == AIModelType.Rerank)
                                            {
                                                <Tag Color="@PresetColor.GeekBlue.ToString()">Rerank重排模型</Tag>
                                            }
                                        </p>
                                    </div>
                                    <div class="listContentItem" style="width:20%">
                                        <b>模型地址</b>
                                        <p title="@context.EndPoint">@context.EndPoint</p>
                                    </div>
                                    <div class="listContentItem" style="width:10%">
                                        <b>模型名称</b>
                                        <p title="@context.ModelName">@context.ModelName</p>
                                    </div>
                                </div>
                            </ListItem>
                        </AntList>
                    </ChildContent>
                </Card>
            </div>
        </ChildContent>
    </PageContainer>
</div>
<style>
.listContentItem {
    width: 20%;
    overflow: hidden; /* 防止内容溢出 */
    text-overflow: ellipsis; /* 超出部分显示省略号 */
    white-space: nowrap; /* 防止内容换行 */
}

/* 为需要显示工具提示的元素设置title属性 */
.listContentItem p[title] {
    cursor: pointer; /* 鼠标移动上去时显示小手势 */
}

/* 悬停样式 */
.listContentItem:hover p[title]:before {
    content: attr(title); /* 使用title属性的内容 */
    position: absolute;
    background: #333; /* 工具提示的背景颜色 */
    color: #fff; /* 工具提示的文字颜色 */
    padding: 4px 8px; /* 工具提示内部的填充 */
    border-radius: 4px; /* 工具提示的边框圆角 */
    text-align: center; /* 工具提示文字居中对齐 */
    z-index: 1000; /* 工具提示在最顶层 */
}
</style>
@code
{
    RenderFragment edit(Action clickAction) =>@<a key="edit" @onclick="@clickAction">修改</a>;
    RenderFragment delete(Action clickAction) =>@<a key="delete" @onclick="@clickAction">删除</a>;
}
